package com.fks.fks_service.mapper;

import com.fks.fks_service.pojo.AddressDB;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface AddressMapper {

    @Select("select * from fks_address where uid=#{userId} and isDelete='0'")
    List<AddressDB> getAddressByUserId(int userId);

    @Update("update fks_address set address=#{address},phone=#{phone},consigneeName=#{consigneeName}" +
            ",isDefault=#{isDefault},updateTime=#{updateTime},longitude=#{longitude},latitude=#{latitude}" +
            " where id=#{id}")
    int updateAddress(AddressDB addressDB);

    @Update("update fks_address set isDelete='1' where id=#{addressId}")
    int deleteAddress(String addressId);

    @Insert("insert into fks_address (uid,address,phone,consigneeName,isDefault,createTime,isDelete" +
            ",province,city,area) " +
            "values (#{uid},#{address},#{phone},#{consigneeName},#{isDefault},#{createTime},'0'" +
            ",#{province},#{province},#{area})")
    int insertAddress(AddressDB addressDB);

    @Select("select * from fks_address where id=#{addressId}")
    AddressDB getAddressById(int addressId);

    @Update("update fks_address set isDefault='1',updateTime=#{updateTime} where id=#{id}")
    int updateDefault(AddressDB addressDB);
}
